#include<bits/stdc++.h>

using namespace std;

const int N  = 2031;

int g[N][N];
bool st[N];
int dist[N];
int n, m;

int dj()
{
	dist[1] = 0;
	
	for(int i = 0; i < n; i ++ )
	{
		int t = -1;
		for(int j = 1; j <= n; j ++ )
			if(!st[j] && (t == -1 || dist[j] < dist[t]))
				t = j;
				
		st[t] = true;
		
		for(int j = 1; j <= n; j ++ )
		{
			dist[j] = min(dist[j], dist[t] + g[t][j]);
		}
	}
	if(dist[n] == 0x3f3f3f3f) return -1;
	return dist[n];
}

int main()
{
	memset(g, 0x3f, sizeof(g));
	memset(dist, 0x3f, sizeof(dist));
	n = 2021;
	for(int i = 1; i <= 2021; i++ )
		for(int j = 1; j <= 21; j ++ )
			g[i][i + j] = (i * (i + j)) / __gcd(i, i + j);
	int ans = dj();
	cout<<ans;
	return 0;
}
